<template>
	<view class="page">
        <block v-if="!wxappReview">
            <uni-forms border>
                <uni-title type="h2" title="投稿中心-请输入内容"></uni-title>
                <uni-easyinput type="textarea" autoHeight v-model="content" placeholder="请输入您要投稿的内容" maxlength="250"></uni-easyinput>
                <uni-title type="h5" :title="notice" color="#999"></uni-title>
                <button type="warn" class="submit-btn" form-type="submit" @click="dosubmit"><text class="iconfont icon-tianjia"></text> 提交</button>
            </uni-forms>
        </block>
        <block v-if="wxappReview">
            <view class="about">
                <view class="about-title"><uni-title type="h1" title="联系我们-(点击相关文字可复制)" color="#027fff"></uni-title></view>
                <view @click="copyText($event,info.qq)"><uni-title type="h3" :title="'QQ：'+info.qq"></uni-title></view>
                <view @click="copyText($event,info.wx)"><uni-title type="h3" :title="'微信号：'+info.wx"></uni-title></view>
                <view @click="copyText($event,info.email)"><uni-title type="h3" :title="'邮箱：'+info.email"></uni-title></view>
                <view @click="copyText($event,info.www)"><uni-title type="h3" :title="'网址：'+info.www"></uni-title></view>
                <view @click="copyText($event,info.desc)"><uni-title type="h3" :title="'简介：'+info.desc"></uni-title></view>
                <view ><image class="about-img" :src="info.img" mode="widthFix"></image></view> 
            </view>
        </block>
	</view>
</template>

<script>
    import util from '@/common/util.js'
	export default {
        onShow:function(){
            let _this = this;
            util.post('/api/content/memberSet',{},function(res){
                let data = res.data;
                // #ifndef H5
                data = JSON.parse(data);
                // #endif
                if( data.code === 1 ){
                    //需要延迟一些才能改变标题
                    setTimeout(function(){
                        uni.setNavigationBarTitle({
                            title: data.data.title
                        });
                    },500);
                    
                    _this.info = data.data.info;
                    _this.wxappReview = data.data.wxapp_review;
                }
            })
        },  
		data(){
			return {
                info:{},
                wxappReview:false,
				content:'',
                notice:'已输入0个字，最长支持250个字符。'
			}
		},
        methods:{
            dosubmit(){
                let reg = /^\s?$/i,_this = this;
                if( reg.test(this.content) ){
                    return util.showError('内容不能为空~');
                }
                uni.showModal({
                    title: '温馨提示',
                    content: '提交后不能修改，您确定要提交吗?',
                    showCancel:true,
                    success(res) {
                        if (res.confirm) {
                           util.post('/api/content/contribute',{content:_this.content},function(res){
                               let data = res.data;
                               // #ifndef H5
                               data = JSON.parse(data);
                               // #endif
                               console.log(data);
                               if( data.code === 1 ){
                                   _this.content = '';
                                   util.showSuccess(data.msg);
                               } else {
                                   util.showError(data.msg);
                               }
                           })
                        } 
                    }
                });
            },
            copyText(e,text) {
            	
            	let content = text;
            	// #ifdef H5
            	this.$copyText(content).then(function(e) {
            		uni.showToast({
            			title: '语录复制成功',
            			duration: 1000
            		});
            	}, function(e) {
            		uni.showToast({
            			title: '复制失败',
            			duration: 1000,
            			icon: "error"
            		});
            	})
            	// #endif
            	// #ifndef H5
            	uni.setClipboardData({
            		data: content,
            		success: function() {
            			uni.showToast({
            				title: '复制成功',
            				duration: 1000
            			});
            		},
            		fail: function() {
            			uni.showToast({
            				title: '复制失败',
            				duration: 1000,
            				icon: "error"
            			});
            		}
            	});
            	// #endif
            },
        },
        watch:{
            /**监听内容变化
             * @param {Object} newVal
             * @param {Object} oldVal
             */
            content(newVal,oldVal){
                this.notice = '已输入'+this.content.length+'字，最长支持250个字符。'
            }
        }
	}
</script>

<style>
    page,.page{background: #FFF;}
    .page{padding-top:80rpx;}
    .submit-btn{border-radius: 8rpx;margin-top: 20rpx;}
    .submit-btn .iconfont{font-size:40rpx;margin-right: 10rpx;}
    .about-title{margin-bottom: 20rpx;}
    .about-img{width:100%;margin:20rpx auto;}
</style>
